package com.xunyin.enums;

/**
 * @author jthong
 * @Description:继电器指令（查询状态）
 * @Version 1.0.0
 * @Date 2020/10/30 15:33
 */
public enum RelayStatusCmdEnum {
    /***
     * 查询4路继电器状态
     */
    RELAY_STATUS_CMD(1, "0101000000043DC9"),
    RELAY_STATUS_ON_02_03(2, "01010106D18A"),
    RELAY_STATUS_ON_01_02_03(2, "01010107104A"),
    RELAY_STATUS_OFF_01_02_03(3, "010101005188");

//    01010106D18A

    private final String name;
    private final int value;

    RelayStatusCmdEnum(int value, String name) {
        this.name = name;
        this.value = value;
    }

    public int getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    public int getIndex() {
        return value;
    }

    public static RelayStatusCmdEnum parse(Integer value) {
        if (value == null) {
            return throwParseException(value);
        }
        for (RelayStatusCmdEnum e : RelayStatusCmdEnum.values()) {
            if (e.getValue() == value) {
                return e;
            }
        }
        return throwParseException(value);
    }

    private static RelayStatusCmdEnum throwParseException(Integer value) {
        throw new IllegalArgumentException(value + " can not parse to " + RelayStatusCmdEnum.class.getName());
    }

    public static String getNameByValue(Integer value) {
        if (value == null) {
            return "";
        }
        for (RelayStatusCmdEnum e : RelayStatusCmdEnum.values()) {
            if (e.getValue() == value) {
                return e.getName();
            }
        }
        return "";
    }
}
